/*
 * Prescription.java
 *
 * Created on August 31, 2008, 1:19 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Hao Hao
 */
public class Prescription {
    
    /** Creates a new instance of Prescription */
private int PrescriptionID;
private String Date;
private int TreatID;
private int DoctorID;
    /**
     *
     * get PrescriptionID
     *@return PrescriptionID
     */
    public int getPrescriptionID() {
        return PrescriptionID;
    }
    /**
     *
     * set PrescriptionID
     */
    public void setPrescriptionID(int PrescriptionID) {
        this.PrescriptionID = PrescriptionID;
    }
    /**
     *
     * get getDate
     *@return getDate
     */
    public String getDate() {
        return Date;
    }
    /**
     *
     * set Date
     */

    public void setDate(String Date) {
        this.Date = Date;
    }


    /**
     *
     * get getTreatID
     *@return getTreatID
     */
    public int getTreatID() {
        return TreatID;
    }

    /**
     *
     * set getTreatID
     */
    public void setTreatID(int TreatID) {
        this.TreatID = TreatID;
    }

    /**
     *
     * get all Prescription
     * @return Vector v
     */
    public int getDoctorID() {
        return DoctorID;
    }

    public void setDoctorID(int DoctorID) {
        this.DoctorID = DoctorID;
    }
    public static Vector getAllPrescription() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllPrescriptions");
            while(rs.next()){
                Prescription p = new Prescription();
                p.setPrescriptionID(rs.getInt(1));
                p.setDate(rs.getString(2));
                p.setTreatID(rs.getInt(3));
                p.setDoctorID(rs.getInt(4));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   


    
    /**
     *
     * get Prescription by PrescriptionID
     * @return Vector v
     */    
    public static Vector getPrescriptionById(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchPrescriptionById", paramList);
            
            while(rs.next()){
                Prescription p = new Prescription();
                p.setPrescriptionID(rs.getInt(1));
                p.setDate(rs.getString(2));
                p.setTreatID(rs.getInt(3));
                p.setDoctorID(rs.getInt(4));
                v.add(p);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     
    
    /**
     *
     * get Prescription by Name Prescription
     * @return Vector v
     */     
    public static Vector getPrescriptionByName(String name) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);
            ResultSet rs = DBHelper.executeQuery("spSearchPrescriptionById", paramList);           
            while(rs.next()){
                Prescription p = new Prescription();
                p.setPrescriptionID(rs.getInt(1));
                p.setDate(rs.getString(2));
                p.setTreatID(rs.getInt(3));
                p.setDoctorID(rs.getInt(4));
                v.add(p);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     

    /**
     *
     * Insert one prescription into table Prescription
     * @return int 
     */ 
    public static int insertPrescription(Prescription p) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(p.Date);
            paramList.add(p.TreatID);   
            paramList.add(p.DoctorID);
            i=DBHelper.executeUpdate("spInsertPrescription",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }              

    /**
     *
     * Update one prescription into table Prescription
     * @return int 
     */     
    public static int updatePrescription(int id, Prescription p) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add((Integer)id);
            paramList.add(p.Date);
            paramList.add(p.TreatID);    
            paramList.add(p.PrescriptionID);
            i=DBHelper.executeUpdate("spUpdatePrescription",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }

    /**
     *
     * Delete one prescription into table Prescription
     * @return int 
     */     
    public static int deletePrescription(int id) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add((Integer)id); 
            i=DBHelper.executeUpdate("spDeletePrescription",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }


    
}
